package com.nuanshui.heatedloan.msgcenter.job;

import com.nuanshui.framework.utils.LogUtil;
import com.nuanshui.heatedloan.msgcenter.constant.SmsMsgBizType;
import com.nuanshui.heatedloan.msgcenter.facade.MsgSender;
import com.nuanshui.heatedloan.msgcenter.integration.AppPushMsgBody;
import com.nuanshui.heatedloan.msgcenter.model.*;
import com.nuanshui.heatedloan.task.annotation.Task;
import com.nuanshui.heatedloan.task.facade.bean.JobParams;
import com.nuanshui.heatedloan.task.facade.bean.JobProvider;
import com.nuanshui.heatedloan.task.failover.TaskfailoverStrategyType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;

@Component
public class PushMsgJob {

	private Logger logger = LoggerFactory.getLogger(PushMsgJob.class);
	
	@Autowired
	private MsgSender msgSender;
	
	/**
	 * 系统管理员推送
	 * @param @param jobParams
	 * @author guohao
	 * @date 2017年1月16日 下午5:24:59
	 * @since $
	 */
	@Task(group="PUSH_MSG",name="ADMIN_PUSH_MSG",failover=TaskfailoverStrategyType.RETRY,retries=1)
	public void adminPushMsg(JobParams jobParams) {
		LogUtil.info(logger, "接到管理员推送任务");
		AppPushMsgBody msgBody = new AppPushMsgBody();
		msgBody.setBizType(SmsMsgBizType.ADMIN_APP_PUSH);
		msgBody.setBizId(jobParams.getBizKey());
		msgBody.setMsgOperationType(MsgOperationType.ADD);
		msgSender.sendPushMsg(msgBody);
		LogUtil.info(logger, "管理员推送任务结束");
	}
	
	public static void main(String[] args) {
		JobProvider jobProvider = new JobProvider("PUSH_MSG", "ADMIN_PUSH_MSG");
		jobProvider.addParams(JobParams.BIZ_KEY, "$id");
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DAY_OF_YEAR, 2);
		//quartzTaskManager.addJob(jobProvider,calendar.getTime());
	}
}
